package com.yijiaw.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yijiaw.domain.About;
import com.yijiaw.service.AboutService;


@Controller
@RequestMapping("/admin/about")
public class AboutController {

	@Autowired
	AboutService aboutService;
	
	@RequestMapping(method = RequestMethod.GET)
	public String about(Model model) {
		List<About> list = aboutService.findAllAbouts(0, 1);
		if (list != null && list.size() > 0) {
			About about = aboutService.findAllAbouts(0, 1).get(0);
			model.addAttribute("about", about);
		}
		return "admin/about";
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public String about(@ModelAttribute About about) {
		aboutService.saveAbout(about);
		return "redirect:about";
	}
	
}
